<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <el-menu-item index="/dashboard">
                <i class="el-icon-s-home"></i>
                <span slot="title">首页</span>
            </el-menu-item>
            <el-submenu
                    :index="index+''"
                    :key="root.authorityName"
                    v-for="(root,index) in rootList">
                <template slot="title">
                    <i :class="root.authorityIco"></i>
                    <span>{{root.authorityName}}</span>
                </template>
                <el-menu-item-group
                        :key="menu.authorityName"
                        v-for="menu in root.children"
                >
                    <template slot="title">{{menu.authorityName}}</template>
                    <el-menu-item
                            :index="child.authorityPath"
                            :key="child.authorityName"
                            v-for="child in menu.children"
                    >{{child.authorityName}}
                    </el-menu-item>
                </el-menu-item-group>
            </el-submenu>
        </el-menu>
    </div>
</template>

<script>
import bus from '../../../utils/bus.js';
export default {
    data() {
        return {
            collapse: false
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        },
        rootList:{
            get(){
                return this.$store.state.menu
            }
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
